//
//  GoodDetailVC.swift
//  ShareUmbrella
//
//  Created by keng fu on 2017/8/22.
//  Copyright © 2017年 尧尚信息科技. All rights reserved.
//

import UIKit
import YSKit
import LPBannerView

class GoodDetailVC: YSBaseViewController {
    
    let bannerView = LPBannerView(frame: .zero)
    
    override func setup() {
        super.setup()
    }
    /*
     *
     * 界面布局初始化
     */
    override func buildUI() {
        super.buildUI()
        self.title = I18n("setting.gooddetail.title")
        
        self.view.backgroundColor = UIColor.init(colorLiteralRed: 230/255.0, green: 230/255.0, blue: 230/255.0, alpha: 1)
        
        let mainScrollView = UIScrollView(frame: UIScreen.main.bounds)
        self.view.addSubview(mainScrollView)
        mainScrollView.backgroundColor = UIColor.clear
        mainScrollView.snp.makeConstraints { (make) in
            make.edges.equalTo(self.view)
        }
        mainScrollView.autoresizingMask = UIViewAutoresizing.flexibleHeight
        mainScrollView.isScrollEnabled = true // 可以上下滚动
        mainScrollView.scrollsToTop = true // 点击状态栏时，可以滚动回顶端
        mainScrollView.bounces = true // 反弹效果，即在最顶端或最底端时，仍然可以滚动，且释放后有动画返回效果
        mainScrollView.isPagingEnabled = false // 分页显示效果
        mainScrollView.showsHorizontalScrollIndicator = true // 显示水平滚动条
        mainScrollView.showsVerticalScrollIndicator = true // 显示垂直滚动条
        mainScrollView.indicatorStyle = UIScrollViewIndicatorStyle.white // 滑动条的样式
        
        bannerView.ys.customize { (view) in
            view.placeholderImage = UIImage(named: "雨伞")!
            mainScrollView.addSubview(view)
            
            view.snp.makeConstraints({ (make) in
                make.top.equalTo(mainScrollView.snp.top)
                make.centerX.equalTo(mainScrollView.snp.centerX)
                make.width.equalTo(UIScreen.main.bounds.width)
                make.height.equalTo(300)
            })
            
            view.clickItemClosure = { (index) -> Void in
                print("闭包回调---\(index)")
            }
            
            // 异步网络请求得到相关数据之后赋值刷新
            let imageArr = ["雨伞", "雨伞", "雨伞"]
            
            view.imagePaths = imageArr // 请求到的图片url字符串或者本地图片名称
        }
        
        bannerView.delegate = self
        
        let introduceView = UIView(frame: .zero).ys.customize { (view) in
            mainScrollView.addSubview(view)
            view.backgroundColor = .white
            
            view.snp.makeConstraints({ (make) in
                make.top.equalTo(bannerView.snp.bottom)
                make.leading.trailing.equalTo(bannerView)
                make.height.equalTo(80)
            })
        }
        
        let _ = UILabel(frame: .zero).ys.customize { (view) in
            introduceView.addSubview(view)
            view.text = "U4YOU乐享伞黑款+附送电池"
            view.font = UIFont.boldSystemFont(ofSize: 20.0)
            view.numberOfLines = 1
            view.textAlignment = .left
            
            view.snp.makeConstraints({ (make) in
                make.top.equalTo(introduceView.snp.top).offset(10)
                make.leading.equalTo(introduceView.snp.leading).offset(20)
                make.trailing.equalTo(introduceView.snp.trailing).offset(-20)
            })
        }
        
        let lblNeedPoint = UILabel(frame: .zero).ys.customize { (view) in
            introduceView.addSubview(view)
            view.text = "所需积分"
            view.font = UIFont.systemFont(ofSize: 15)
            view.numberOfLines = 1
            view.textAlignment = .left
            
            view.snp.makeConstraints({ (make) in
                make.bottom.equalTo(introduceView.snp.bottom).offset(-10)
                make.leading.equalTo(introduceView.snp.leading).offset(20)
            })
        }
        
        let _ = UILabel(frame: .zero).ys.customize { (view) in
            introduceView.addSubview(view)
            view.text = "200分"
            view.font = UIFont.systemFont(ofSize: 17)
            view.numberOfLines = 1
            view.textColor = UIColor.init(colorLiteralRed: 251/255.0, green: 175/255.0, blue: 81 / 255.0, alpha: 1)
            view.textAlignment = .left
            
            view.snp.makeConstraints({ (make) in
                make.centerY.equalTo(lblNeedPoint.snp.centerY)
                make.leading.equalTo(lblNeedPoint.snp.trailing).offset(100)
            })
        }
        
        let detailView = UIView(frame: .zero).ys.customize { (view) in
            mainScrollView.addSubview(view)
            view.backgroundColor = .white
            
            view.snp.makeConstraints({ (make) in
                make.top.equalTo(introduceView.snp.bottom).offset(30)
                make.leading.trailing.equalTo(introduceView)
                make.height.equalTo(150)
            })
        }
        
        let _ = UILabel(frame: .zero).ys.customize { (view) in
            detailView.addSubview(view)
            view.text = "基本信息"
            view.font = UIFont.boldSystemFont(ofSize: 17.0)
            view.numberOfLines = 1
            view.textAlignment = .left
            
            view.snp.makeConstraints({ (make) in
                make.top.equalTo(detailView.snp.top).offset(10)
                make.leading.equalTo(detailView.snp.leading).offset(20)
                make.trailing.equalTo(detailView.snp.trailing).offset(-20)
            })
        }
        
        let line = UIView(frame: .zero).ys.customize { (view) in
            detailView.addSubview(view)
            view.backgroundColor = UIColor.init(colorLiteralRed: 230/255.0, green: 230/255.0, blue: 230/255.0, alpha: 1)

            view.snp.makeConstraints({ (make) in
                make.top.equalTo(detailView.snp.top).offset(50)
                make.leading.trailing.equalTo(detailView)
                make.height.equalTo(1)
            })
        }
        
        let _ = UILabel(frame: .zero).ys.customize { (view) in
            detailView.addSubview(view)
            view.text = "U4YOU乐享伞黑款+附送电池"
            view.font = UIFont.systemFont(ofSize: 17)
            view.textAlignment = .left
            
            view.snp.makeConstraints({ (make) in
                make.top.equalTo(line.snp.top).offset(20)
                make.leading.equalTo(detailView.snp.leading).offset(20)
                make.trailing.equalTo(detailView.snp.trailing).offset(-20)
            })
        }

    }
    
    //
    override func buildRx() {
        super.buildRx()
    }
}

extension GoodDetailVC: LPBannerViewDelegate{
    func cycleScrollView(_ scrollView: LPBannerView, didSelectItemAtIndex index: Int){
        
    }
}
